package arm_search;

import data.Seed;
import data.TermCollection;
import data.email.EmailSeed;
import data.email.EmailSummaryWriter;
import data.email.EmailTokenCounter;
import java.io.File;
import java.util.ArrayList;
import process.email.EmailIndexGenerator;

/**
 * Kelas algoritma utama program ARM_Search
 * @author Muqtafi Akhmad
 */
public class ARM_Search {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        if (args.length != 3) {
            System.out.print("## Invalid argument count, arguments should be <database_directory> <n_top_term> <n_thread>");
            System.exit(1);
        }
        // mendapatkan directory file email
        String databaseDirectory = args[0];
        // mendapatkan jumlah top token yang diinginkan
        Integer topTokenCount = Integer.parseInt(args[1]);
        // mendapatkan jumlah thread untuk memproses file email
        Integer threadCount = threadCount = Integer.parseInt(args[2]);
        Seed rootSeed = new EmailSeed(databaseDirectory);
        ArrayList<String> seedFilter = new ArrayList<String>();
        // filter all_documents
        seedFilter.add("all_documents");
        EmailIndexGenerator instance = new EmailIndexGenerator(threadCount);
        EmailTokenCounter passedTokenCounter = new EmailTokenCounter();
        // membaca koleksi terms dari semua dokumen
        System.out.println("## Reading statistics for directory " + databaseDirectory);
        long startTime = System.currentTimeMillis(), endTime;
        TermCollection terms = instance.doGenerateIndex(rootSeed, seedFilter, passedTokenCounter);
        EmailSummaryWriter summaryWriter = new EmailSummaryWriter();
        // menuliskan summary pembacaan term
        summaryWriter.writeSummary(terms, topTokenCount, (new File(".")).getAbsolutePath(), passedTokenCounter);
        endTime = System.currentTimeMillis();
        System.out.println("## Statistics reading finished , elapsed time " + ((endTime - startTime) / 1000) + " seconds");
        System.exit(0);
    }
}
